<html>
<head>
<link href="https://moi.maxis.com.my/MaxisSSO/MaxisStyle.css" rel="stylesheet" type="text/css">
<!-- <link href="https://121.123.149.199/MaxisSSO/MaxisStyle.css" rel="stylesheet" type="text/css"> -->
</head>

<%@ page import="com.checkfree.isolutions.customer.persist.*" %>
<%@ page import="com.checkfree.isolutions.statement.*" %>
<%@ page import="com.checkfree.isolutions.statement.persist.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.controller.*" %>
<%@ page import="com.checkfree.isolutions.property.Properties" %>
<%@ page import="com.checkfree.isolutions.property.PropertiesConfig" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.controller.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.maxis.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.utils.*" %>

<%@ page import="org.xml.sax.InputSource" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.Exception" %>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="my.com.wsClient.*" %>
<%@ page import="my.com.maxis.dao.*" %>

<body>
<!--
... CP site webpage content code.......
-->
<form name="ssoForm" method="post" action="SsoMyPhoneBook.jsp">
<div class="Maxis_style" id="MaxisDIV">
	<table class="tablestyle300">
		<tr>
			<td>
				<input  id="SSOSID"   name="SSOSID"  type="hidden"  onchange="CPDOSomething();"/>
			</td>
			<td>
				<input  id="SSOFID"   name="SSOFID"  type="hidden"/>
			</td>
			<td>
				<input  id="RETRY"   name="RETRY"  type="hidden"/>
			</td>
		</tr>
	</table>
</div>
</form>
<!--
... CP site webpage content code.......
-->
<%
	String sretry = (String)EbppxUtil.nullToEmpty(request.getParameter("RETRY"));
	int retry = 0;
	if(!sretry.equals("") || sretry == null){
		retry = Integer.parseInt(sretry) + 1;
	}
	System.out.println("retry = "+retry);
	if(retry <= 10){
		//Get attribute from session for the logon user
		final EbppxEcsUser ecsu = (EbppxEcsUser) session.getAttribute(EbppxConstants.ECS_USER);
		String sid = (String)session.getAttribute("sid");
		String fid= (String)session.getAttribute("fid");
		String hs = (String)session.getAttribute("hs");
		String ssoSid= (String)request.getParameter("SSOSID");
		String ssoFid = (String)request.getParameter("SSOFID");


		/*File f = new File("D:/Workspace/Maxis/EBPS/sso/data/response.xml");
		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document doc = docBuilder.parse(f);
		//Node root = doc.getDocumentElement();

		NodeList nodeList = doc.getElementsByTagName("GetLOBInfo_XMLResult");
		Node root = (Element)nodeList.item(0);*/

		my.com.maxis.dao.LobOutputDao objOutput = null;
		//objOutput = DOMParser.retrieveValue00(root, 1);

		String cpId = "526s9943DdhkytbsH25k";
		//String userId = request.getParameter("userId");

		if(sid==null || sid.equals("0") || sid.equals("")){
			sid = request.getParameter("sid");
			fid= request.getParameter("fid");
			hs = request.getParameter("hs");
			session.setAttribute("sid",sid);
			session.setAttribute("fid",fid);
			session.setAttribute("hs",hs);
		}
		if(sid==null || sid.equals("0") || sid.equals("")){
			sid = ssoSid;
			fid= ssoFid;
		}
		System.out.println("User Id:"+ecsu.getUserId());
		System.out.println("sid:"+sid);
		System.out.println("fid:"+fid);
		System.out.println("hs:"+hs);

		if(sid!=null && !sid.equals("0") && !sid.equals("")){
			if(fid!=null && !fid.equals("0") && !fid.equals("")){
				maxisSSOClient ssoClient = new maxisSSOClient();
				objOutput = ssoClient.service(sid,fid,ecsu.getUserId(),cpId,"");
			}
		}

		/*File f = new File("D:/Workspace/Maxis/EBPS/sso/data/response.xml");
		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document doc = docBuilder.parse(f);
		//Node root = doc.getDocumentElement();

		NodeList nodeList = doc.getElementsByTagName("GetLOBInfo_XMLResult");
		Node root = (Element)nodeList.item(0);

		LobOutputDao objOutput = new LobOutputDao();
		objOutput = DOMParser.retrieveValue00(root, 1);*/

		if(objOutput!=null){
		// Print output
		System.out.println("....Start print output....");

		System.out.println("Status = " + objOutput.getStatus());
		System.out.println("Error_Code = " + objOutput.getErrCode());
		System.out.println("Error_Msg = " + objOutput.getErrMsg());

		//ecsu.setUserId("aaa");
		//ecsu.setEmail(userId);
				System.out.println("ecsu.getUserId = " + ecsu.getUserId());
				System.out.println("ecsu.getEmail = " + ecsu.getEmail());

				System.out.println("ecsu.getEmail1 = " + ecsu.getEmail());
			ArrayList listAcc = objOutput.getAccount();
			for (int i = 0; i < listAcc.size(); i++) {
				my.com.maxis.dao.AccountInfoDao objAccInfo = new my.com.maxis.dao.AccountInfoDao();
				objAccInfo = (my.com.maxis.dao.AccountInfoDao) listAcc.get(i);

				System.out.println("acctExtID = " + objAccInfo.getAcctExtID());
				String strOldAccountKey = AcctDetails.getOldAccountKey(objAccInfo.getAcctExtID());
				ecsu.setAccount(objAccInfo.getAcctExtID());
				ecsu.setOldAccount(strOldAccountKey);

				ecsu.setAccessType("S");

				ArrayList listAccDetails = objAccInfo.getAcctDetails();
				for (int j = 0; j < listAccDetails.size(); j++) {
					my.com.maxis.dao.AccountDetailsInfoDao objAccDetailsInfo = new my.com.maxis.dao.AccountDetailsInfoDao();
					objAccDetailsInfo = (my.com.maxis.dao.AccountDetailsInfoDao) listAccDetails.get(j);


					System.out.println("MSISDN = " + objAccDetailsInfo.getMsisdn());
					System.out.println("ServiceStatus = " + objAccDetailsInfo.getServiceStatus());
					System.out.println("LOB = " + objAccDetailsInfo.getLob());
					System.out.println("Package = " + objAccDetailsInfo.getPackage());
					System.out.println("PrinSuppInd = " + objAccDetailsInfo.getPrinSuppInd());
					System.out.println("PostPreInd = " + objAccDetailsInfo.getPostPreInd());
					System.out.println("SSOStatus = " + objAccDetailsInfo.getSSOStatus());

					if(objAccDetailsInfo.getPrinSuppInd().equals("P")){
						ecsu.setAccessType("P");
					}
				}
			}
			System.out.println("....End print output...."+session);
			session.setAttribute(EbppxConstants.ECS_USER, ecsu);
			response.sendRedirect(response.encodeRedirectURL("CusPhoneBookList_v1r00"));
		}
	}else{
		session.setAttribute("errorMessage","Failed to connecting SSO, please try again later.");
		response.sendRedirect(response.encodeRedirectURL("Error.jsp"));
	}		
%>
<script type="text/javascript">
	var cpid='526s9943DdhkytbsH25k';
</script>

<script type="text/javascript">
   function CPDOSomething() {
   		document.ssoForm.RETRY.value = <%=retry%>;
	   document.ssoForm.submit();
   }
</script>
<!-- <script type="text/javascript" src="https://121.123.149.199/MaxisSSO/easyXDM/easyXDM.js"></script> -->
<!-- <script type="text/javascript" src="https://121.123.149.199/MaxisSSO/easyXDM/json2.js"></script> -->
<!-- <script type="text/javascript" src="https://121.123.149.199/MaxisSSO/maxisScript_v3.js"></script> -->
<script type="text/javascript" src="https://moi.maxis.com.my/MaxisSSO/easyXDM/easyXDM.js"></script>
<script type="text/javascript" src="https://moi.maxis.com.my/MaxisSSO/easyXDM/json2.js"></script>
<script type="text/javascript" src="https://moi.maxis.com.my/MaxisSSO/maxisScript_v3.js"></script>
</body>
</html>